package com.tedu.charging.service.bill.controller;


import com.tedu.charging.common.pojo.web.ServerResult;
import com.tedu.charging.service.bill.pojo.param.BillParam;
import com.tedu.charging.service.bill.pojo.param.DeviceSelfCheckResultParam;
import com.tedu.charging.service.bill.pojo.vo.BillDetailVO;
import com.tedu.charging.service.bill.service.IChargingBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/charge/ChargingBill")
@CrossOrigin
@Slf4j
public class ChargingBillController {
    @Autowired
    IChargingBillService chargingBillService;

    @GetMapping("/createBill")
    public ServerResult<String> createBill(BillParam billParam) throws Throwable {
        String billId = chargingBillService.createBill(billParam);
        return new ServerResult(0,"创建订单成功",billId);
    }

    @PostMapping("/chargingSuccess")
    //如果参数是string,knife接口中不显示{},需要把string放在一个实体类中
    public ServerResult<Boolean> chargingSuccess(@RequestBody DeviceSelfCheckResultParam deviceSelfCheckResultParam){
        boolean result = chargingBillService.chagringSuccess(deviceSelfCheckResultParam.getBillId());
        return ServerResult.success(result);
    }
    //订单失败
    @PostMapping("/chargingFail")
    public ServerResult<Boolean> chargingFail(@RequestBody DeviceSelfCheckResultParam deviceSelfCheckResultParam){
        boolean result = chargingBillService.chagringFail(deviceSelfCheckResultParam.getBillId());
        return ServerResult.success(result);
    }

    @GetMapping("/normalStopBill")
    public ServerResult<BillDetailVO> normalStopBill(String billId){
        BillDetailVO billDetailVO = chargingBillService.normalStopBill(billId);


        return ServerResult.success("停止成功",billDetailVO);
    }
}
